package com.sk.weichat.bean.collection;

import android.os.Parcel;
import android.os.Parcelable;

import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.sk.weichat.bean.message.XmppMessage;

import java.util.Objects;

/**
 * Created by Administrator on 2017/10/20 0020.
 * 收藏
 */

public class CollectionEvery implements MultiItemEntity, Parcelable {

    // 各种type混乱，收藏的type, 生活圈消息的type, xmpp消息的type, 数值都不一样，
    public static final int TYPE_IMAGE = 1;
    public static final int TYPE_VIDEO = 2;
    public static final int TYPE_FILE = 3;
    public static final int TYPE_VOICE = 4;
    public static final int TYPE_TEXT = 5;
    public static final int TYPE_LINK = 6; // 链接

    private long createTime;
    private String emojiId = "";
    private String msg = "";
    private String fileName = "";
    private int fileLength;
    private long fileSize;
    private String url = "";
    private String collectContent = "";
    private int type;
    private String userId = "";

    private String fromNickName = "";
    private int fromUserId;


    //用户名字
    private String name = "";

    //是否可删除
    public boolean deleteAble = false;
    //是否可选择
    public boolean isEdit = false;
    //
    public boolean isChecked = false;


    public CollectionEvery() {

    }

    protected CollectionEvery(Parcel in) {
        createTime = in.readLong();
        emojiId = in.readString();
        msg = in.readString();
        fileName = in.readString();
        fileLength = in.readInt();
        fileSize = in.readLong();
        url = in.readString();
        collectContent = in.readString();
        type = in.readInt();
        userId = in.readString();
        fromNickName = in.readString();
        fromUserId = in.readInt();
        name = in.readString();
        isEdit = in.readByte() != 0;
        isChecked = in.readByte() != 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(createTime);
        dest.writeString(emojiId);
        dest.writeString(msg);
        dest.writeString(fileName);
        dest.writeInt(fileLength);
        dest.writeLong(fileSize);
        dest.writeString(url);
        dest.writeString(collectContent);
        dest.writeInt(type);
        dest.writeString(userId);
        dest.writeString(fromNickName);
        dest.writeInt(fromUserId);
        dest.writeString(name);
        dest.writeByte((byte) (isEdit ? 1 : 0));
        dest.writeByte((byte) (isChecked ? 1 : 0));
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<CollectionEvery> CREATOR = new Creator<CollectionEvery>() {
        @Override
        public CollectionEvery createFromParcel(Parcel in) {
            return new CollectionEvery(in);
        }

        @Override
        public CollectionEvery[] newArray(int size) {
            return new CollectionEvery[size];
        }
    };

    // type转成xmpp使用的那一套，
    // 项目里有几套type都不同，而且都是用int没有enum, 异常情况没考虑，直接抛异常，
    public int getXmppType() {
        int type;
        switch (getType()) {
            case CollectionEvery.TYPE_TEXT:
                type = XmppMessage.TYPE_TEXT;
                break;
            case CollectionEvery.TYPE_IMAGE:
                type = XmppMessage.TYPE_IMAGE;
                break;
            case CollectionEvery.TYPE_FILE:
                type = XmppMessage.TYPE_FILE;
                break;
            case CollectionEvery.TYPE_VIDEO:
                type = XmppMessage.TYPE_VIDEO;
                break;
            case CollectionEvery.TYPE_VOICE:
                type = XmppMessage.TYPE_VOICE;
                break;
            default:
                throw new IllegalStateException("类型<" + getType() + ">不存在，");
        }
        return type;
    }

    public long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(long createTime) {
        this.createTime = createTime;
    }

    public String getEmojiId() {
        return emojiId;
    }

    public void setEmojiId(String emojiId) {
        this.emojiId = emojiId;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public int getFileLength() {
        return fileLength;
    }

    public void setFileLength(int fileLength) {
        this.fileLength = fileLength;
    }

    public long getFileSize() {
        return fileSize;
    }

    public void setFileSize(long fileSize) {
        this.fileSize = fileSize;
    }

    public String getCollectContent() {
        return collectContent;
    }

    public void setCollectContent(String collectContent) {
        this.collectContent = collectContent;
    }

    @Override
    public int getItemType() {
//        if (type == TYPE_FILE) {
//            String fileName = getFileName();
//            String suffix = "";
//            try {
//                suffix = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());
//            } catch (Exception e) {
//
//            }
//            if (suffix.equals("jpg") || suffix.equals("jpeg") || suffix.equals("png")) {
//                type = TYPE_IMAGE;
//            }
//        }
        return type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof CollectionEvery)) return false;
        CollectionEvery that = (CollectionEvery) o;
        return createTime == that.createTime &&
                fileLength == that.fileLength &&
                fileSize == that.fileSize &&
                type == that.type &&
                Objects.equals(emojiId, that.emojiId) &&
                Objects.equals(msg, that.msg) &&
                Objects.equals(fileName, that.fileName) &&
                Objects.equals(url, that.url) &&
                Objects.equals(collectContent, that.collectContent) &&
                Objects.equals(userId, that.userId) &&
                Objects.equals(name, that.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(createTime, emojiId, msg, fileName, fileLength, fileSize, url, collectContent, type, userId, name);
    }


    public String getFromNickName() {
        return fromNickName;
    }

    public void setFromNickName(String fromNickName) {
        this.fromNickName = fromNickName;
    }

    public int getFromUserId() {
        return fromUserId;
    }

    public void setFromUserId(int fromUserId) {
        this.fromUserId = fromUserId;
    }
}
